package com.fastadmin.mapper.impl;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.fastadmin.pojo.Keep;
import com.xphsc.easyjdbc.EasyJdbcTemplate;
import com.xphsc.easyjdbc.core.exception.JdbcDataException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Slf4j
public class KeepMapper {
    @Autowired
    EasyJdbcTemplate easyJdbcTemplate;


    public boolean findByOpenidAndAyiId(String openid, Long ayi_id) {
        List<Keep> keeps = easyJdbcTemplate.find("SELECT * FROM t_keep WHERE type=1 AND openid=? AND ayi_id =? ", Keep.class, openid, ayi_id);
        return keeps.size() > 0;
    }

    public void save(Keep keep) {
        try {
            easyJdbcTemplate.insert(keep);
        } catch (Exception e) {
            log.debug("收藏重复了！{}", ExceptionUtil.stacktraceToString(e));

        }
    }

    public void deleteByNoAndOpenIdAndState(Long no, String openid, int state) {
        String sql = "DELETE FROM t_keep WHERE ayi_id = ? AND openid = ? AND type =?";
        this.easyJdbcTemplate.getJdbcTemplate().update(sql, no, openid, state);
    }
}
